//复写零
//测试链接 https://leetcode.cn/problems/duplicate-zeros/description/
public class DuplicateZeros {
    public void duplicateZeros(int[] nums) {
        int dest = -1;
        int cur = 0;
        int n = nums.length -1;
        //先找到最后一个复写的数
        while(cur <=n){
            if(nums[cur] !=0){  //不为0，dest走一步
                dest++;
            }else{  //为0,dest走两步
                dest+=2;
            }
            if(dest >= n){  //dest以及走到最后一位了
                break;
            }
            cur++;
        }//循环结束cur指向最后一个复写的值
        if(dest == n+1){ //处理边界情况
            nums[n] = 0;
            cur--;
            dest-=2;
        }
        //从后往前填写
        while(cur>=0 ){
            if(nums[cur] != 0){
                nums[dest--] = nums[cur];
            }else{
                nums[dest--] = 0;
                nums[dest--] = 0;
            }
            cur--;
        }
    }
}
